﻿using MediatR;
using Production_Set.API.Application.Commands.Resourctes;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.DemandPlanning;
using THE_WIND_RISES.Common.Domans.Produce.Resources;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Set.API.MaterialManagement.State
{
    //审批
    public class TaskStateHandler : IRequestHandler<TaskStateCommend, Result>
    {
        private readonly IBaseRepository<ProductionTasks> ProductionTasks;
        public TaskStateHandler(IBaseRepository<ProductionTasks> productionTasks)
        {
            ProductionTasks = productionTasks;
        }

        public async Task<Result> Handle(TaskStateCommend request, CancellationToken cancellationToken)
        {
            var results = new Result() { Code = (int)CommonErrorCodes.Update };

            string sql = "UPDATE ProductionTasks SET Pid=@Pid WHERE TasksId=" + request.TasksId;
            var list = ProductionTasks.Update(sql, new
            {
                Pid = request.Pid + 1
            });
            if (list != null)
            {
                results.Code = (int)CommonErrorCodes.Success;
                results.Msg = "修改成功";
            }

            return results;
        }
    }
}
